<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="../css/all.min.css" rel="stylesheet">
    <title>通用试卷模版</title>
    <style>
        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            line-height: 1.6;
            margin: 0;
            padding: 20px;
            position: relative;
            background-color: #fff;
        }
        .exam-container {
            max-width: 900px;
            margin: 0 auto;
            padding: 30px;
            background-color: white;
            box-shadow: 0 0 20px rgba(0, 0, 0, 0.15);
            border-radius: 10px;
            position: relative;
            animation: fadeIn 0.5s ease-out;
        }
        @keyframes fadeIn {
            from {
                opacity: 0;
                transform: translateY(-20px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }
        .exam-header {
            text-align: center;
            margin-bottom: 25px;
            padding-bottom: 15px;
            border-bottom: 3px solid #ccc;
        }
        .exam-title {
            font-size: 32px;
            font-weight: bold;
            margin-bottom: 8px;
            text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
            padding: 5px;
        }
        .candidate-info {
            margin-bottom: 25px;
            padding: 15px;
            border: 1px solid #ddd;
            background-color: #f9f9f9;
            border-radius: 4px;
            display: flex;
            flex-wrap: wrap;
            justify-content: space-between;
        }
        .info-row {
            width: 100%;
            display: flex;
            margin-bottom: 8px;
            flex-wrap: wrap;
        }
        .info-item {
            display: flex;
            width: 48%;
            margin-bottom: 8px;
        }
        .info-label {
            width: 80px;
            font-weight: bold;
            flex-shrink: 0;
        }
        .info-content {
            flex: 1;
            border-bottom: 1px dotted #999;
            min-height: 20px;
        }
        .instructions {
            font-size: 14px;
            color: #666;
            margin-bottom: 25px;
            padding: 10px 15px;
            background-color: #f0f7ff;
            border-left: 4px solid #ccc;
            border-radius: 0 4px 4px 0;
            position: relative;
        }
        .score-table {
            background-color: #fff;
            padding: 5px 10px;
            border: 1px solid #ddd;
            border-radius: 4px;
            margin-bottom: 20px;
        }
        .score-table table {
            border-collapse: collapse;
            width: 100%;
        }
        .score-table th, .score-table td {
            border: 1px solid #ddd;
            padding: 8px;
            text-align: center;
            height: 40px;
        }
        .section {
            margin-bottom: 35px;
        }
        .section-title {
            font-size: 22px;
            font-weight: bold;
            margin-bottom: 18px;
            padding-bottom: 8px;
            border-bottom: 1px solid #e0e0e0;
        }
        .question {
            margin-bottom: 25px;
            padding-bottom: 15px;
            border-bottom: 1px dashed #e0e0e0;
            transition: all 0.3s ease;
            position: relative;
        }
        .question:hover {
            background-color: #f9f9f9;
            transform: scale(1.01);
        }
        .question-title {
            font-weight: bold;
            margin-bottom: 12px;
            font-size: 16px;
        }
        .question-content {
            margin-left: 20px;
            margin-bottom: 15px;
        }
        .question-options {
            margin-left: 30px;
        }
        .question-points {
            float: right;
            color: #ff6600;
            font-weight: bold;
        }
        .answer-area {
            margin-left: 30px;
            min-height: 60px;
            padding: 10px;
            border: none;
            border-bottom: 1px dashed #999;
            background-color: transparent;
            margin-top: 10px;
            transition: all 0.3s ease;
            width: calc(100% - 40px);
        }
        .code-block {
            background-color: #f5f5f5;
            border: 1px solid #ddd;
            padding: 10px;
            font-family: "Courier New", monospace;
            border-radius: 4px;
            margin: 10px 0;
            overflow-x: auto;
        }
        .option {
            margin-bottom: 8px;
            padding-left: 5px;
            cursor: pointer;
            transition: all 0.3s ease;
        }
        .option:hover {
            background-color: #f0f7ff;
            transform: translateX(5px);
        }
        .network-diagram {
            text-align: center;
            margin: 15px 0;
            padding: 10px;
            background-color: #f9f9f9;
            border: 1px dashed #ccc;
            border-radius: 4px;
        }
        .network-diagram img {
            max-width: 100%;
            height: auto;
        }
        .diagram-caption {
            font-size: 14px;
            color: #666;
            margin-top: 5px;
        }
        #control-panel {
            position: fixed;
            right: 20px;
            top: 50%;
            transform: translateY(-50%);
            padding: 15px;
            background-color: white;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
            z-index: 100;
            display: flex;
            flex-direction: column;
            gap: 15px;
        }
        #control-panel button,
        .custom-file-input label {
            padding: 10px 15px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            font-size: 14px;
            box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
            transition: all 0.3s ease;
            text-align: center;
            white-space: nowrap;
        }
        #control-panel button:hover,
        .custom-file-input label:hover {
            background: linear-gradient(135deg, #5a6ec2 0%, #683f8b 100%);
        }
        .custom-file-input {
            position: relative;
            display: inline-block;
            width: 100%;
        }
        .custom-file-input input[type="file"] {
            position: absolute;
            left: 0;
            top: 0;
            opacity: 0;
            width: 100%;
            height: 100%;
            cursor: pointer;
        }
        .editable {
            padding: 2px 5px;
            cursor: text;
            outline: none;
            border-radius: 3px;
        }
        .editable:focus {
            background-color: #f0f7ff;
            box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.3);
        }
        .answer-highlight {
            background-color: #e6f7ff;
            border-left: 3px solid #1890ff;
            padding: 5px 10px;
            margin: 5px 0;
        }
        .modal {
            display: none;
            position: fixed;
            z-index: 1000;
            left: 0;
            top: 0;
            width: 100%;
            height: 100%;
            overflow: auto;
            background-color: rgba(0, 0, 0, 0.4);
        }
        .modal-content {
            background-color: #fefefe;
            margin: 15% auto;
            padding: 20px;
            border: 1px solid #888;
            width: 30%;
            border-radius: 10px;
            box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
            animation-name: animatetop;
            animation-duration: 0.4s;
        }
        @keyframes animatetop {
            from {
                top: -300px;
                opacity: 0;
            }
            to {
                top: 0;
                opacity: 1;
            }
        }
        .close {
            color: #aaa;
            float: right;
            font-size: 28px;
            font-weight: bold;
        }
        .close:hover,
        .close:focus {
            color: black;
            text-decoration: none;
            cursor: pointer;
        }
        @media print {
            #control-panel {
                display: none;
            }
            body {
                background-color: white;
                padding: 0;
            }
            .exam-container {
                box-shadow: none;
                padding: 20px;
                max-width: 100%;
            }
            .answer-area {
                background-color: white;
                min-height: 50px;
                border-bottom: 1px solid #ddd;
            }
            .question:hover {
                transform: none;
                background-color: transparent;
            }
        }
        @media (max-width: 768px) {
            .exam-container {
                padding: 15px;
            }
            .exam-title {
                font-size: 24px;
            }
            .section-title {
                font-size: 20px;
            }
            .info-item {
                width: 100%;
            }
            #control-panel {
                right: 10px;
                padding: 10px;
            }
            #control-panel button,
            .custom-file-input label {
                padding: 8px 12px;
                font-size: 13px;
            }
            .modal-content {
                width: 80%;
            }
        }
    </style>
</head>
<body>
    <div class="exam-container">
        <div class="exam-header">
            <div class="exam-title editable" id="exam-title" contenteditable="true">面试考试</div>
            <div>（考试时间：90分钟　　总分：100分）</div>
        </div>
        <div class="candidate-info">
            <div class="info-row">
                <div class="info-item">
                    <div class="info-label">姓名：</div>
                    <div class="info-content"></div>
                </div>
                <div class="info-item">
                    <div class="info-label">职位：</div>
                    <div class="info-content"></div>
                </div>
            </div>
            <div class="info-row">
                <div class="info-item">
                    <div class="info-label">电话：</div>
                    <div class="info-content"></div>
                </div>
                <div class="info-item">
                    <div class="info-label">日期：</div>
                    <div class="info-content"></div>
                </div>
            </div>
        </div>
        <div class="score-table">
            <table>
                <tr>
                    <th>选择题</th>
                    <th>填空题</th>
                    <th>判断题</th>
                    <th>简答题</th>
                    <th>论述题</th>
                    <th>总分</th>
                </tr>
                <tr>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                </tr>
            </table>
        </div>
        <div class="instructions">
            <p><strong>考试说明：</strong></p>
            <p>1. 本考试包含选择题、填空题、判断题、简答题和论述题五种题型；</p>
            <p>2. 请仔细阅读题目要求，按要求作答，并在规定时间内提交答卷。</p>
        </div>
        <div id="examContent" style="display: none;">
            <div class="section">
                <h2 class="section-title">一、选择题（请从各题所给的选项中，选择正确的答案，将其选项填写在题后的括号内。每题1分，共20分。）</h2>
                <div id="multipleChoiceQuestions"></div>
            </div>
            <div class="section">
                <h2 class="section-title">二、填空题（请将正确答案填写在横线上。每题2分，共20分）</h2>
                <div id="fillInTheBlankQuestions"></div>
            </div>
            <div class="section">
                <h2 class="section-title">三、判断题（判断下列表述的正误，正确的打"√"，错误的打"×"，将答案填写在对应题目后的括号内。每题1分，共10分）</h2>
                <div id="trueFalseQuestions"></div>
            </div>
            <div class="section">
                <h2 class="section-title">四、简答题（请根据题目要求，简明扼要、条理清晰地阐述相关内容，完整回答问题要点。每题6分，共30分）</h2>
                <div id="shortAnswerQuestions"></div>
            </div>
            <div class="section">
                <h2 class="section-title">五、论述题（请根据题目要求，详细论述相关内容。每题10分，共20分）</h2>
                <div id="essayQuestions"></div>
            </div>
        </div>
    </div>
    <div id="control-panel">
        <button id="download-button" onclick="download()">题库模版</button>
        <div class="custom-file-input">
            <input type="file" id="jsonFileInput" accept=".json">
            <label for="jsonFileInput">选择题库</label>
        </div>
        <button id="fill-answers-button" onclick="fillAnswers()">填充答案</button>
        <button id="print-button" onclick="window.print()">打印试卷</button>
    </div>
    <div id="myModal" class="modal">
        <div class="modal-content">
            <span class="close">&times;</span>
            <p id="modal-message"></p>
        </div>
    </div>
    <script>
        let currentExamData = null;
        const jsonFileInput = document.getElementById('jsonFileInput');
        const examContent = document.getElementById('examContent');
        const examTitle = document.getElementById('exam-title');
        const modal = document.getElementById('myModal');
        const span = document.getElementsByClassName("close")[0];
        const modalMessage = document.getElementById('modal-message');
        span.onclick = function () {
            modal.style.display = "none";
        }
        window.onclick = function (event) {
            if (event.target == modal) {
                modal.style.display = "none";
            }
        }
        function showModal(message) {
            modalMessage.textContent = message;
            modal.style.display = "block";
        }
        jsonFileInput.addEventListener('change', function (event) {
            const file = event.target.files[0];
            if (file) {
                const reader = new FileReader();
                reader.onload = function (e) {
                    try {
                        currentExamData = JSON.parse(e.target.result);
                        generateExam(currentExamData);
                        examContent.style.display = 'block';
                    } catch (error) {
                        showModal('解析 JSON 文件时出错，请检查文件格式是否正确。');
                        console.error('解析 JSON 文件时出错:', error);
                    }
                };
                reader.readAsText(file);
            }
        });
        function generateExam(examData) {
            const multipleChoiceQuestions = document.getElementById('multipleChoiceQuestions');
            const fillInTheBlankQuestions = document.getElementById('fillInTheBlankQuestions');
            const trueFalseQuestions = document.getElementById('trueFalseQuestions');
            const shortAnswerQuestions = document.getElementById('shortAnswerQuestions');
            const essayQuestions = document.getElementById('essayQuestions');
            multipleChoiceQuestions.innerHTML = '';
            fillInTheBlankQuestions.innerHTML = '';
            trueFalseQuestions.innerHTML = '';
            shortAnswerQuestions.innerHTML = '';
            essayQuestions.innerHTML = '';
            if (examData['选择题'] && examData['选择题'].length > 0) {
                const shuffledMultipleChoice = shuffleArray(examData['选择题']).slice(0, 20);
                shuffledMultipleChoice.forEach((question, index) => {
                    const questionDiv = document.createElement('div');
                    questionDiv.classList.add('question');
                    questionDiv.dataset.answer = question.答案 || '';
                    questionDiv.innerHTML = `
                        <div class="question-title">
                            ${index + 1}. ${question.题目}（&nbsp;&nbsp;&nbsp;&nbsp;）
                        </div>
                        <div class="question-options">
                            ${question.选项 ? question.选项.map((option, optionIndex) => `
                                <div class="option">
                                    ${option}
                                </div>
                            `).join('') : '<div>题目格式错误，缺少选项</div>'}
                        </div>
                        <div class="answer-highlight" style="display: none;">正确答案: ${question.答案 || '无答案'}</div>
                    `;
                    multipleChoiceQuestions.appendChild(questionDiv);
                });
            } else {
                multipleChoiceQuestions.innerHTML = '<p>题库中没有选择题数据</p>';
            }
            if (examData['填空题'] && examData['填空题'].length > 0) {
                const shuffledFillInTheBlank = shuffleArray(examData['填空题']).slice(0, 10);
                shuffledFillInTheBlank.forEach((question, index) => {
                    const questionDiv = document.createElement('div');
                    questionDiv.classList.add('question');
                    questionDiv.dataset.answer = question.答案 || '';
                    questionDiv.innerHTML = `
                        <div class="question-title">
                            ${index + 1}. ${question.题目 || '题目加载错误'}
                        </div>
                        <div class="answer-area" style="min-height: 30px;"></div>
                        <div class="answer-highlight" style="display: none;">正确答案: ${question.答案 || '无答案'}</div>
                    `;
                    fillInTheBlankQuestions.appendChild(questionDiv);
                });
            } else {
                fillInTheBlankQuestions.innerHTML = '<p>题库中没有填空题数据</p>';
            }
            if (examData['判断题'] && examData['判断题'].length > 0) {
                const shuffledTrueFalse = shuffleArray(examData['判断题']).slice(0, 10);
                shuffledTrueFalse.forEach((question, index) => {
                    const questionDiv = document.createElement('div');
                    questionDiv.classList.add('question');
                    questionDiv.dataset.answer = question.答案 || '';
                    questionDiv.innerHTML = `
                        <div class="question-title">
                            ${index + 1}. ${question.题目 || '题目加载错误'}（&nbsp;&nbsp;&nbsp;&nbsp;）
                        </div>
                        <div class="answer-highlight" style="display: none;">正确答案: ${question.答案 || '无答案'}</div>
                    `;
                    trueFalseQuestions.appendChild(questionDiv);
                });
            } else {
                trueFalseQuestions.innerHTML = '<p>题库中没有判断题数据</p>';
            }
            if (examData['简答题'] && examData['简答题'].length > 0) {
                const shuffledShortAnswer = shuffleArray(examData['简答题']).slice(0, 5);
                shuffledShortAnswer.forEach((question, index) => {
                    const questionDiv = document.createElement('div');
                    questionDiv.classList.add('question');
                    questionDiv.dataset.answer = question.答案 || '';
                    questionDiv.innerHTML = `
                        <div class="question-title">
                            ${index + 1}. ${question.题目 || '题目加载错误'}
                        </div>
                        <div class="answer-area"></div>
                        <div class="answer-highlight" style="display: none;">参考答案: ${question.答案 || '无答案'}</div>
                    `;
                    shortAnswerQuestions.appendChild(questionDiv);
                });
            } else {
                shortAnswerQuestions.innerHTML = '<p>题库中没有简答题数据</p>';
            }
            if (examData['论述题'] && examData['论述题'].length > 0) {
                const shuffledEssay = shuffleArray(examData['论述题']).slice(0, 2);
                shuffledEssay.forEach((question, index) => {
                    const questionDiv = document.createElement('div');
                    questionDiv.classList.add('question');
                    questionDiv.dataset.answer = question.答案 || '';
                    questionDiv.innerHTML = `
                        <div class="question-title">
                            ${index + 1}. ${question.题目 || '题目加载错误'}
                        </div>
                        <div class="answer-area" style="min-height: 150px;"></div>
                        <div class="answer-highlight" style="display: none;">参考答案: ${question.答案 || '无答案'}</div>
                    `;
                    essayQuestions.appendChild(questionDiv);
                });
            } else {
                essayQuestions.innerHTML = '<p>题库中没有论述题数据</p>';
            }
        }
        function shuffleArray(array) {
            if (!array) return [];
            const newArray = [...array];
            for (let i = newArray.length - 1; i > 0; i--) {
                const j = Math.floor(Math.random() * (i + 1));
                [newArray[i], newArray[j]] = [newArray[j], newArray[i]];
            }
            return newArray;
        }
        function download() {
            const template = {
                "选择题": [
                    {
                        "题目": "示例选择题题目",
                        "选项": ["选项A", "选项B", "选项C", "选项D"],
                        "答案": "A"
                    }
                ],
                "填空题": [
                    {
                        "题目": "示例填空题题目，请在横线处填写答案：______",
                        "答案": "示例答案"
                    }
                ],
                "判断题": [
                    {
                        "题目": "示例判断题题目",
                        "答案": "正确"
                    }
                ],
                "简答题": [
                    {
                        "题目": "示例简答题题目",
                        "答案": "示例答案"
                    }
                ],
                "论述题": [
                    {
                        "题目": "示例论述题题目",
                        "答案": "示例答案"
                    }
                ]
            };
            const json = JSON.stringify(template, null, 2);
            const blob = new Blob([json], { type: 'application/json' });
            const url = URL.createObjectURL(blob);
            const a = document.createElement('a');
            a.href = url;
            a.download = 'exam_template.json';
            document.body.appendChild(a);
            a.click();
            document.body.removeChild(a);
            URL.revokeObjectURL(url);
        }
        function fillAnswers() {
            if (!currentExamData) {
                showModal('请先加载题库文件！');
                return;
            }
            const mcQuestions = document.querySelectorAll('#multipleChoiceQuestions .question');
            mcQuestions.forEach((question, index) => {
                const answerDiv = question.querySelector('.answer-highlight');
                if (answerDiv) {
                    answerDiv.style.display = 'block';
                }
                const title = question.querySelector('.question-title');
                if (title) {
                    const answer = question.dataset.answer;
                    title.innerHTML = title.innerHTML.replace(/（&nbsp;&nbsp;&nbsp;&nbsp;）/, `（<span style="color: red;">${answer}</span>）`);
                }
            });
            const fibQuestions = document.querySelectorAll('#fillInTheBlankQuestions .question');
            fibQuestions.forEach((question, index) => {
                const answerDiv = question.querySelector('.answer-highlight');
                if (answerDiv) {
                    answerDiv.style.display = 'block';
                }
                const answerArea = question.querySelector('.answer-area');
                if (answerArea) {
                    answerArea.innerHTML = `<span style="color: red;">${question.dataset.answer}</span>`;
                }
            });
            const tfQuestions = document.querySelectorAll('#trueFalseQuestions .question');
            tfQuestions.forEach((question, index) => {
                const answerDiv = question.querySelector('.answer-highlight');
                if (answerDiv) {
                    answerDiv.style.display = 'block';
                }
                const title = question.querySelector('.question-title');
                if (title) {
                    const answer = question.dataset.answer;
                    title.innerHTML = title.innerHTML.replace(/（&nbsp;&nbsp;&nbsp;&nbsp;）/, `（<span style="color: red;">${answer === '正确' ? '√' : '×'}</span>）`);
                }
            });
            const saQuestions = document.querySelectorAll('#shortAnswerQuestions .question');
            saQuestions.forEach((question, index) => {
                const answerDiv = question.querySelector('.answer-highlight');
                if (answerDiv) {
                    answerDiv.style.display = 'block';
                }
                const answerArea = question.querySelector('.answer-area');
                if (answerArea) {
                    answerArea.innerHTML = `<span style="color: red;">${question.dataset.answer}</span>`;
                }
            });
            const essayQuestions = document.querySelectorAll('#essayQuestions .question');
            essayQuestions.forEach((question, index) => {
                const answerDiv = question.querySelector('.answer-highlight');
                if (answerDiv) {
                    answerDiv.style.display = 'block';
                }
                const answerArea = question.querySelector('.answer-area');
                if (answerArea) {
                    answerArea.innerHTML = `<span style="color: red;">${question.dataset.answer}</span>`;
                }
            });
        }
        examTitle.addEventListener('focus', function () {
            this.classList.add('editing');
        });
        examTitle.addEventListener('blur', function () {
            this.classList.remove('editing');
        });
    </script>
</body>
</html>